package org.bsplus.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class Issue extends AbstractEntity
{
	@Basic(optional = false)
	private String summary;

	@Basic(optional = false)
	private String description;

	@ManyToOne(optional = false)
	private IssueType issueType;

	@ManyToOne(optional = false)
	private Project project;

	@Basic(optional = false)
	private Long issueNumber;

	@ManyToOne(optional = false)
	private IssueStatus issueStatus;

	@ManyToOne(optional = false)
	private User assignee;

	@ManyToOne(optional = false)
	private IssueSeverity issueSeverity;

	@Basic(optional = false)
	@Temporal(TemporalType.DATE)
	private Date created = new Date();

	@ManyToOne(optional = false)
	private User createdBy;

	@OneToMany
	private List<Comment> comments = new ArrayList<Comment>();

	/**
	 * @return the summary
	 */
	public String getSummary()
	{
		return summary;
	}

	/**
	 * @param summary
	 *            the summary to set
	 */
	public void setSummary(String summary)
	{
		this.summary = summary;
	}

	/**
	 * @return the description
	 */
	public String getDescription()
	{
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description)
	{
		this.description = description;
	}

	/**
	 * @return the issueType
	 */
	public IssueType getIssueType()
	{
		return issueType;
	}

	/**
	 * @param issueType
	 *            the issueType to set
	 */
	public void setIssueType(IssueType issueType)
	{
		this.issueType = issueType;
	}

	/**
	 * @return the issueNumber
	 */
	public Long getIssueNumber()
	{
		return issueNumber;
	}

	/**
	 * @param issueNumber
	 *            the issueNumber to set
	 */
	public void setIssueNumber(Long issueNumber)
	{
		this.issueNumber = issueNumber;
	}

	/**
	 * @return the project
	 */
	public Project getProject()
	{
		return project;
	}

	/**
	 * @param project
	 *            the project to set
	 */
	public void setProject(Project project)
	{
		this.project = project;
	}

	/**
	 * @return the issueStatus
	 */
	public IssueStatus getIssueStatus()
	{
		return issueStatus;
	}

	/**
	 * @param issueStatus
	 *            the issueStatus to set
	 */
	public void setIssueStatus(IssueStatus issueStatus)
	{
		this.issueStatus = issueStatus;
	}

	/**
	 * @return the assignee
	 */
	public User getAssignee()
	{
		return assignee;
	}

	/**
	 * @param assignee
	 *            the assignee to set
	 */
	public void setAssignee(User assignee)
	{
		this.assignee = assignee;
	}

	/**
	 * @return the issueSeverity
	 */
	public IssueSeverity getIssueSeverity()
	{
		return issueSeverity;
	}

	/**
	 * @param issueSeverity
	 *            the issueSeverity to set
	 */
	public void setIssueSeverity(IssueSeverity issueSeverity)
	{
		this.issueSeverity = issueSeverity;
	}

	/**
	 * @return the created
	 */
	public Date getCreated()
	{
		return created;
	}

	/**
	 * @param created
	 *            the created to set
	 */
	public void setCreated(Date created)
	{
		this.created = created;
	}

	/**
	 * @return the createdBy
	 */
	public User getCreatedBy()
	{
		return createdBy;
	}

	/**
	 * @param createdBy
	 *            the createdBy to set
	 */
	public void setCreatedBy(User createdBy)
	{
		this.createdBy = createdBy;
	}

	/**
	 * @return the comments
	 */
	public List<Comment> getComments()
	{
		return comments;
	}

	/**
	 * @param comments
	 *            the comments to set
	 */
	public void setComments(List<Comment> comments)
	{
		this.comments = comments;
	}

        public String getDisplayIssueNumber()
        {
            return getProject().getCode() + "-" + getIssueNumber();
        }
}
